<template>
	<view>
		<view class="lists">
			<block v-for="(item,index) in addressList" :key="index">
			<view class="list">
				<view class="list_info" @tap="selectAddress(item.id)">
					<text>{{item.uname}}</text>
					<text>{{item.uphone}}</text>
				</view>
				<view class="list_address">
					<view class="address_left" @tap="selectAddress(item.id)">
						<text class="default" v-if="item.state==1">默认</text>
						<text class="address">{{item.province}}{{item.city}}{{item.district}}{{item.uaddress}}</text>
					</view>
					<view class="address_right" @tap="editAddress(item.id)">
						<image src="../../static/address_edit.png"></image>
					</view>
				</view>
			</view>
			</block>
			
		</view>
		<view class="address_add" @tap="addAddress()">
			新增地址
		</view>
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				addressList:[]
			}
		},
		// onLoad:function(option){
		// 	uni.request({
		// 		url: request.common.baseUrl+'/api/address/isAddress',
		// 		data: {
		// 			token:uni.getStorageSync('keyToken')
		// 		},
		// 		header: {
		// 			'Content-Type':'application/json;charset=UTF-8',
		// 			'Content-Type':'application/x-www-form-urlencoded'
		// 		},
		// 		success: (res) => {
		// 			if(res.data.code==200){
		// 				for (var j = 0; j < res.data.data.length; j++) {
		// 					this.addressList.push(res.data.data[j])
		// 				}
		// 			}
		// 		}
		// 	});
		// },
		onShow:function(){
			uni.request({
				url: request.common.baseUrl+'/api/address/isAddress',
				data: {
					token:uni.getStorageSync('keyToken')
				},
				header: {
					'Content-Type':'application/json;charset=UTF-8',
					'Content-Type':'application/x-www-form-urlencoded'
				},
				success: (res) => {
					if(res.data.code==200){
						this.addressList=[]
						for (var j = 0; j < res.data.data.length; j++) {
							this.addressList.push(res.data.data[j])
						}
					}
				}
			});
		},
		methods: {
			addAddress(){
				uni.navigateTo({
					url: '/pages/member/member'
				});
			},
			editAddress(id){
				uni.navigateTo({
					url: '/pages/member/member?id='+id
				});
			},
			selectAddress(id){
				uni.request({
					url: request.common.baseUrl+'/api/address/selectAddress',
					data: {
						token:uni.getStorageSync('keyToken'),
						id:id
					},
					header: {
						'Content-Type':'application/json;charset=UTF-8',
						'Content-Type':'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if(res.data.code==200){
							uni.navigateBack({
								delta: 1
							})
						}
					}
				});
			}
		}
	}
</script>

<style>
.lists{
	width:690upx;
	margin:0 30upx;
}
.list{
	width:690upx;
	height:140upx;
	border-bottom:1upx solid #f6f6f6;
}
.list_info{
	width:690upx;
	height:50upx;
	padding-top:20upx;
}
.list_info text:nth-child(1){
	font-size:32upx;
	color:#333333;
}
.list_info text:nth-child(2){
	font-size:24upx;
	color:#333333;
	margin-left:25upx;
}
.list_address{
	width:690upx;
	height:50upx;
}
.address_left{
	float:left;
}
.address_left .default{
	background-color:#ff6101;
	color:#FFFFFF;
	font-size:20upx;
	border-radius:20upx;
	padding:0 15upx;
	margin-right:10upx;
}
.address_left .address{
	font-size:20upx;
	color:#999999;
	width:500upx;
	overflow:hidden;
	text-overflow:ellipsis;
	white-space:nowrap;
}
.address_right{
	width:50upx;
	height:50upx;
	float:right;
}
.address_right image{
	width:40upx;
	height:40upx;
}
.address_add{
	position:fixed;
	width:100%;
	bottom:0;
	height:80upx;
	background-color:#FF6101;
	color:#FFFFFF;
	text-align:center;
	line-height:80upx;
}
</style>
